package top.zhangjianyong.tools.utils;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import javax.swing.text.html.Option;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Optional;

/**
 * @author zhangjianyong
 * @since 2025/3/24 下午4:07
 */
public class AnnotationUtil {
    public static <T extends Annotation> T getAnnotation(ProceedingJoinPoint point, Class<T> clazz) {
        Signature signature = point.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method method = methodSignature.getMethod();
        if (method == null) return null;
        T annotation = method.getAnnotation(clazz);//方法注解
        if (annotation != null) return annotation;
        return method.getDeclaringClass().getAnnotation(clazz);//类注解
    }
}
